/*
 * Copyright 2002-2016 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.lntea.lnblog.common;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Bean工厂类
 * @author lichao
 * @date 2016/6/30 18:54
 */
public class BeanFactory {
    // beanName和bean对象的Map
    private static ConcurrentHashMap<String, Object> beanMap = new ConcurrentHashMap<String, Object>();
    // bean class和bean对象的Map
    private static ConcurrentHashMap<Class, Object> beanClassMap = new ConcurrentHashMap<Class, Object>();
    // bean名称list
    private static List<String> beanNameList = new ArrayList<String>();

    /**
     * 根据bean名称获取对应的对象
     * @param beanName
     * @return
     */
    public static Object getBean(String beanName){
        return beanMap.get(beanName);
    }

    /**
     * 根据bean的Class对象获取bean对象
     * @param clazz
     * @return
     */
    public static Object getBean(Class clazz){
        return beanClassMap.get(clazz);
    }
}
